<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>Grade Bay</title>
		<link rel="stylesheet" href="gui.css" type="text/css" />
		<!--[if IE 7]>
			<link rel="stylesheet" href="css/ie7.css" type="text/css" />
		<![endif]-->
	</head>
	<body>
		<div class="page">
			<div class="header">
				<a href="index.php" id="logo"><img src="images/gradeBaylogo.png" width="330" height="79" alt=""/></a>
				<ul>
					<li class="selected"><a href="">ADD STUDENT</a></li>
					
				
				</ul>
			</div>
			<div class="body">
                            
                            <?php

                               
                            
                                        include 'PHPClasses/DBAccess.php';
                                        include 'PHPClasses/StudentDBAccess.php';
                                        include 'PHPClasses/Student.php';
                                        
                                        error_reporting(E_ERROR | E_PARSE);
                                                
                                        if ($_POST['submitted']==1)
                                        { 
                                            $DBAccess=new StudentDBAccess();
                                            $Student=new Student();
                                            $Student->setStudentName($_POST["name"]);
                                            $Student->setStudentLevel($_POST["Level"]);
                                            $Student->setAge($_POST["age"]);
                                            $Student->setGender($_POST["gender"]);
                                            $Student->setAddress($_POST["address"]);
                                            $contact=$_POST["contact"];
                                            $Student->setContactNum($contact);
                                            
                                            $errormsg=$DBAccess->validate($Student,FALSE);
                                        
                                            if ($errormsg){ //If any errors display them  
                                                header("Location: http://localhost/paragox-infinity-introse/createStudentProfile.php?error=".$errormsg."&something=".sizeof($contact));
                                            }
                                            else
                                            {
                                                $DBAccess->addToDB($Student);
                                                $DBAccess->addContactsToDB($Student);
                                                
                                                   echo "<script> 
                                                        if(confirm('Successfully Added! Create some more student profiles?')){
                                                                window.location='http://localhost/paragox-infinity-introse/createStudentProfile.php';
                                                        }

                                                        else{
                                                            window.location='http://localhost/paragox-infinity-introse/viewStudentList.php';
                                                            }   

                                                        </script>"; 
            
                                            }
                                            $DBAccess->DBDisconnect(); 
                                        }
                                        
?>         
                            
                            
                            		
			</div>
			
		</div>
	</body>
</html>  